{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">名字：</label>
                            <div class="layui-input-block">
                                <input type="text" name="good_name" lay-verify="required" placeholder="名字" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="good_thumb" id="lay-img" lay-verify="image">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        <!--大分类品牌和门店 start -->
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择分类：</label>
                            <div class="layui-input-block">
                                <select name="good_s_t_id"  lay-search="" lay-filter="types" id="types" lay-verify="required">
                                    <option value="">---- 请选择分类 ----</option>
                                    {foreach name="type1" item="t"}
                                    <option value="{$t.t_id}" >{$t.t_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择品牌：</label>
                            <div class="layui-input-block">
                                <select name="good_s_pp_id"  lay-search="" lay-filter="pps" id="type_pps" lay-verify="required">

                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择门店：</label>
                            <div class="layui-input-block" id="type_sss">
                            </div>
                        </div>
                        <!--大分类品牌和门店 end -->
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">商品分类：</label>
                            <div class="layui-input-block">
                                <select name="good_t_id" lay-search=""  lay-verify="required" id="msg1">
                                    <!--<option value="">请选择商品分类</option>-->
                                    <!--{foreach name="types" item="v"}-->
                                    <!--<option value="{$v.st_id}">{$v.st_name}({$v.st_remark})</option>-->
                                    <!--{/foreach}-->
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">商品品牌：</label>
                            <div class="layui-input-block">
                                <select name="good_pp_id" lay-search=""  lay-verify="required" id="msg2">
                                    <!--<option value="">请选择商品品牌</option>-->
                                    <!--{volist name='pps' id='t'}-->
                                    <!--<option value="{$t.spp_id}">{$t.spp_name}({$t.spp_remark})</option>-->
                                    <!--{/volist}-->
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">商品风格：</label>
                            <div class="layui-input-block">
                                <select name="good_style_id" lay-search=""  lay-verify="required" id="msg3">
                                    <!--<option value="">请选择商品风格</option>-->
                                    <!--{volist name='styles' id='t'}-->
                                    <!--<option value="{$t.sstyle_id}">{$t.sstyle_name}({$t.sstyle_remark})</option>-->
                                    <!--{/volist}-->
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">价格文案：</label>
                            <div class="layui-input-block">
                                <input type="text" name="good_money_name" lay-verify="required" placeholder="价格文案，如：活动价" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">价格：</label>
                            <div class="layui-input-block">
                                <input type="text" value="" style="width: 100px;display: inline;"
                                       name="good_money_min" placeholder="最低" class="layui-input"
                                       oninput="value=value.replace(/[^\d]/g,'')">
                                —
                                <input type="text" value="" style="width: 100px;display: inline;"
                                       name="good_money_max" placeholder="最高" class="layui-input"
                                       oninput="value=value.replace(/[^\d]/g,'')">
                                &nbsp;&nbsp;填写最小与最大值，单位：元
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">排序值</label>
                            <div class="layui-input-block">
                                <input type="number" placeholder="值越大越靠前" value="1" name="good_sort" maxlength="11" class="layui-input" lay-verify="number" >
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">添加
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    wk.uploadImg({size: 5, type: 'png,jpg,jpeg', url: "{:url('Upload/upload')}", domain: ""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('goodAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(types)', function(data){
            $.ajax({
                url:"{:url('admin/Store/getDatas')}",
                dataType:"json",
                data:'t_id=' + data.value,
                type:'post',
                success:function(res){
                    var opt = '';
                    $.each(res.msg,function(key,vo){
                        opt = opt+"<option value="+vo.pp_id+">"+vo.pp_name+"</option>";
                    });
                    $("#type_pps").empty();
                    $("#type_sss").empty();
                    $("#msg1").empty();
                    $("#msg2").empty();
                    $("#msg3").empty();
                    $("#type_pps").append('<option value="">---- 请选择品牌 ----</option>');
                    $("#type_pps").append(opt);
                    form.render('select');
                }
            })
        });
        form.on('select(pps)', function(data){
            $.ajax({
                url:"{:url('admin/Cases/getDatas2')}",
                dataType:"json",
                data:'pp_id=' + data.value,
                type:'post',
                success:function(res){
                    var opt = '';
                    $.each(res.msg,function(key,vo){
//                        opt = opt+"<option value="+vo.s_id+">"+vo.s_name+"</option>";
                        opt = opt+"<input type='checkbox' class='inputinput' value="+vo.s_id+" name='good_s_id[]'  title="+vo.s_name+" />";
                    });
                    $("#type_sss").empty();
                    $("#type_sss").append(opt);
                    form.render('checkbox');
                    //11
                    var opt = '';
                    $.each(res.msg1,function(key,vo){
                        opt = opt+"<option value="+vo.st_id+">"+vo.st_name+"</option>";
                    });
                    $("#msg1").empty();
                    $("#msg1").append('<option value="">---- 请选择产品分类 ----</option>');
                    $("#msg1").append(opt);
                    //22
                    var opt = '';
                    $.each(res.msg2,function(key,vo){
                        opt = opt+"<option value="+vo.spp_id+">"+vo.spp_name+"</option>";
                    });
                    $("#msg2").empty();
                    $("#msg2").append('<option value="">---- 请选择产品品牌 ----</option>');
                    $("#msg2").append(opt);
                    //33
                    var opt = '';
                    $.each(res.msg3,function(key,vo){
                        opt = opt+"<option value="+vo.sstyle_id+">"+vo.sstyle_name+"</option>";
                    });
                    $("#msg3").empty();
                    $("#msg3").append('<option value="">---- 请选择产品风格 ----</option>');
                    $("#msg3").append(opt);
                    form.render('select');

                }
            })
        });
    });
</script>

</body>
</html>
